<?php


namespace App\Model\Dao;

use App\Model\Entity\Manager;
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Db\DB;
use Swoft\Http\Session\HttpSession;

/**
 * 管理员操作
 * @Bean(name="ManagerDao")
 * @package App\Model\Dao
 */
class ManagerDao
{
    /**
     * 通过用户名获取用户信息
     * @param $username
     * @return object|\Swoft\Db\Eloquent\Builder|\Swoft\Db\Eloquent\Model|null
     */
    public function getUserFromUsername($username){
        return Manager::where('username', $username)->select('id','username','password')->first();
    }

    /**
     * 密码更新
     * @param $password
     * @return bool
     */
    public function updatePassword($password){
        $userId = HttpSession::current()->get('userid');
        $result = Manager::find($userId)->update(['password' => password_hash($password, PASSWORD_DEFAULT)]);
        if($result){
            return true;
        }
        return false;
    }
}
